package com.xkstream.client.ui;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.xkstream.client.R;
import com.xkstream.client.base.BaseActivity;
import com.xkstream.client.ui.adapter.CustomPagerAdapter;
import com.xkstream.client.utils.AsyncImage;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xiaoyi on 2017-11-14.
 */

public class ShowImagesActivity extends BaseActivity {
    @BindView(R.id.viewpager)
    ViewPager viewPager;


    String[] images;

    CustomPagerAdapter adapter;
    int index = 0;

    @Override
    protected void initViews(Bundle savedInstanceState) {
        setContentView(R.layout.activity_showimages);
        ButterKnife.bind(this);
        images = getIntent().getStringArrayExtra("images");
        index = getIntent().getIntExtra("index", 0);
        generateImageViews();
    }


    private void generateImageViews() {
        List<View> views = new ArrayList<>();
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
                , ViewGroup.LayoutParams.MATCH_PARENT);
        for (String image : images) {
            ImageView child = new ImageView(this);
            child.setLayoutParams(params);
            AsyncImage.loadPhoto(this, image, child);
            views.add(child);
        }
        adapter = new CustomPagerAdapter(views);
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(index);
    }

    @OnClick(R.id.ivBack)
    public void onClick(View view){
        finish();
    }
}
